﻿using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using RayD.Core;
using RayD.Repository.Core;

namespace RayD.Repository.Entites.SystemModule
{
    [Table("BASE_POST")]
    public class PostEntity : BaseTreeModel<PostEntity>
    {
        #region 实体成员
        /// <summary>
        /// 主键
        /// </summary>
        [Key]
        [Column("B_POSTID")]
        public string B_PostId { get; set; }
        /// <summary>
        /// 上级主键
        /// </summary>
        [Column("B_PARENTID")]
        public string B_ParentId { get; set; }
        /// <summary>
        /// 岗位名称
        /// </summary>
        [Column("B_NAME")]
        public string B_Name { get; set; }
        /// <summary>
        /// 岗位编号
        /// </summary>
        [Column("B_ENCODE")]
        public string B_EnCode { get; set; }
        /// <summary>
        /// 公司主键
        /// </summary>
        [Column("B_MANAFRAMEID")]
        public string B_ManaframeId { get; set; }
        /// <summary>
        /// 部门主键
        /// </summary>
        [Column("B_DEPARTMENTID")]
        public string B_DepartmentId { get; set; }
        /// <summary>
        /// 删除标记
        /// </summary>
        /// <returns></returns>
        [Column("B_ENABLEDMARK")]
        public EnabledMark? B_EnabledMark { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        /// <returns></returns>
        [Column("B_DESCRIPTION")]
        public string B_Description { get; set; }
        /// <summary>
        /// 创建日期
        /// </summary>
        /// <returns></returns>
        [Column("B_CREATEDATE")]
        public DateTime? B_CreateDate { get; set; }
        /// <summary>
        /// 创建用户主键
        /// </summary>
        /// <returns></returns>
        [Column("B_CREATEUSERID")]
        public string B_CreateUserId { get; set; }
        /// <summary>
        /// 创建用户
        /// </summary>
        /// <returns></returns>
        [Column("B_CREATEUSERNAME")]
        public string B_CreateUserName { get; set; }
        /// <summary>
        /// 修改日期
        /// </summary>
        /// <returns></returns>
        [Column("B_MODIFYDATE")]
        public DateTime? B_ModifyDate { get; set; }
        /// <summary>
        /// 修改用户主键
        /// </summary>
        /// <returns></returns>
        [Column("B_MODIFYUSERID")]
        public string B_ModifyUserId { get; set; }
        /// <summary>
        /// 修改用户
        /// </summary>
        /// <returns></returns>
        [Column("B_MODIFYUSERNAME")]
        public string B_ModifyUserName { get; set; }
        #endregion

        #region 扩展操作
        /// <summary>
        /// 新增调用
        /// </summary>
        public void Create()
        {
            if (this.B_ParentId.IsEmpty())
            {
                this.B_ParentId = "0";
            }
            if (this.B_EnabledMark.IsEmpty())
            {
                this.B_EnabledMark = EnabledMark.Enabled;
            }
            this.B_PostId = Guid.NewGuid().ToString();
            this.B_CreateDate = DateTime.Now.ToCstTime();
            UserInfo userInfo = AuthenticationHelper.LoginUserInfo;
            this.B_CreateUserId = userInfo.userId;
            this.B_CreateUserName = userInfo.realName;
        }
        /// <summary>
        /// 编辑调用
        /// </summary>
        public void Modify()
        {
            if (this.B_ParentId.IsEmpty())
            {
                this.B_ParentId = "0";
            }
            this.B_ModifyDate = DateTime.Now.ToCstTime();
            UserInfo userInfo = AuthenticationHelper.LoginUserInfo;
            this.B_ModifyUserId = userInfo.userId;
            this.B_ModifyUserName = userInfo.realName;
        }
        #endregion

        #region 扩展属性
        /// <summary>
        /// 部门名称
        /// </summary>
        [NotMapped]
        public string DepartmentName { get; set; }
        #endregion

        #region 树型配置
        [NotMapped]
        public override string id { get => this.B_PostId; }
        [NotMapped]
        public override string parentId { get => this.B_ParentId; }
        [NotMapped]
        public override string value { get => this.B_PostId; }
        [NotMapped]
        public override string label { get => this.B_Name; }
        #endregion
    }
}
